package com.hzlj.position.locate.converter;

import cn.hutool.core.date.DateUtil;
import com.fz.common.base.converter.ModelDTOConverter;
import com.fz.common.base.core.date.DateUtils;
import com.hzlj.position.locate.common.dto.reportAudio.ReportAudioDTO;
import com.hzlj.position.locate.common.dto.reportAudio.ReportAudioPhoneAddDTO;
import com.hzlj.position.locate.common.enums.ReportAudioType;
import com.hzlj.position.locate.common.model.ReportAudio;

import java.util.Date;

import static com.hzlj.position.config.config.IdConfig.POSITION_ID_GEN;

/**
 * 通信联络核查-电话核查(ReportAudioPhone)DTO转换类
 *
 * @author makejava
 * @date 2024-04-22 11:16:28
 */
public class ReportAudioConverter {
    public static ReportAudio from(ReportAudioPhoneAddDTO dto) {
        Date now = DateUtils.now();
        return ModelDTOConverter.from(dto, ReportAudio.class, (ReportAudio l) -> {
            l.setId(POSITION_ID_GEN.nextIdStr());
            l.setBelongDay(DateUtil.beginOfDay(now));
            l.setReportAudioType(ReportAudioType.PHONE.getType());
            l.setValid(true);
            l.setUpdateTime(now);
            l.setCreateTime(now);
        });
    }

    public static ReportAudio from(ReportAudioDTO dto) {
        Date now = DateUtils.now();
        return ModelDTOConverter.from(dto, ReportAudio.class, (ReportAudio l) -> {
            l.setId(POSITION_ID_GEN.nextIdStr());
            l.setBelongDay(DateUtil.beginOfDay(dto.getReportTime()));
            l.setReportAudioType(ReportAudioType.AUDIO.getType());
            l.setValid(true);
            l.setUpdateTime(now);
            l.setCreateTime(now);
        });
    }

}
